#include <stdio.h>
#include <stdlib.h>
typedef struct ListNode{
	int val;
	struct ListNode *next;
}ListNode,*List;
ListNode* ListInit(){
	ListNode *pHead = (ListNode*)malloc(sizeof(ListNode));//这是一个头结点存储数据的链表
	pHead->val = -1;//表示这个节点为存储数据。
	pHead->next = NULL;
	return pHead;
}
List ListCreate(ListNode* pHead,int val){ //采用头插法插入数据
	if(pHead == NULL){
		return NULL;//假如传入的是空链表。
	}
	else if(pHead->val == -1){//假如要存入第一个数据
		pHead->val = val;
		return pHead;
	}
	ListNode *newNode = (ListNode*)malloc(sizeof(ListNode));
	newNode->val = val;
	newNode->next = pHead;
	pHead = newNode;
	return pHead;
}
void PrintList(ListNode* pHead){
	ListNode* p = pHead;
	while(p){
		printf("%d\n",p->val);
		p = p->next;
	}
}
List ReverseList(struct ListNode* pHead,int start,int end ) { 
	// write code here
	ListNode *p = pHead;
	ListNode *pHead2 = ListInit();
	ListNode *temp = NULL;
	int i = 1;
	while(i>=start&&i<=end){
		pHead2 = ListCreate(pHead2, p->val);
		temp = p;
		p = p->next;
		free(temp);
		i++;
	}
	return pHead2;
}
List ReverseList2(struct ListNode* pHead ) { 
	// write code here
	ListNode *p = pHead;
	ListNode *pHead2 = (ListNode*)malloc(sizeof(ListNode));//这是一个头结点存储数据的链表
	pHead2->val = -1;//表示这个节点为存储数据。
	pHead2->next = NULL;
	
	ListNode *temp = NULL;
	while(p){
		if(pHead2 == NULL){
			p->next = NULL;//假如传入的是空链表。
		}
		else if(pHead2->val == -1){//假如要存入第一个数据
			pHead2->val = p->val;
			break;
		}
		ListNode *newNode = (ListNode*)malloc(sizeof(ListNode));
		newNode->val = p->val;
		newNode->next = pHead2;
		pHead2 = newNode;
		temp = p;
		p = p->next;
		free(temp);
	}
	return pHead2;
}
int main(int argc, char *argv[]) {
	ListNode* pHead = ListInit();
	int val;
	while(scanf("%d",&val)!=EOF && val!=-1){
		pHead = ListCreate(pHead, val);
	}
	int start,end;
	scanf("%d%d",&start,&end);
	printf("倒置前的链表:\n");
	PrintList(pHead);
	pHead = ReverseList(pHead,start,end);
	printf("倒置后的链表:\n");
	PrintList(pHead);
}